<?php
require("inc/header.php");
$mysqli = dbconnect();

$filename = $_FILES['file']['name'];
$filesize = urlencode($_FILES['file']['size']);
$filehash = urlencode(hash_file('sha1',$_FILES['file']['tmp_name'],false));
$title = $_POST['title']; 
$ip = urlencode($_SERVER['REMOTE_ADDR']);
$agent = urlencode($_SERVER['HTTP_USER_AGENT']);

if (verifyextension($_FILES['file']['name']) && ($_FILES['file']['size'] < 50331648))
  {
  if ($_FILES['file']['error'] > 0)
    {
    echo '<h1>Oops!</h1>There was a problem uploading your file. Please report this error along with the following error details to the <a href="contact">'.$sitename.' team</a>.<br />Error details: '.$_FILES['file']['error'].'<br />>';
    }
  else
    {
$query = "INSERT INTO uploads (filename,filesize,filehash,ip,user_agent,title) VALUES(?, ?, ?, ?, ?, ?)";
$statement = $mysqli->stmt_init();
if ($statement->prepare($query))
{
$statement->bind_param("ssssss", $filename, $filesize, $filehash, $ip, $agent, $title);
$statement->execute();
$ID = $statement->insert_id;
$statement->close();
$mysqli->close();
} else {
error_log("Error during upload: $mysqli->error", 3, "$logsdir/error.log");
$statement->close();
$mysqli->close();
echo "0";
}
    if ($ID > 0)
    {
        if (file_exists($uploadsDir.$ID))
          {
          echo '.$ID. already exists.>';
          }
        else
          {
          move_uploaded_file($_FILES['file']['tmp_name'],$uploadsDir.$ID);
          if ($multiserver == true)
           {
           file_get_contents("http://$SQLMaster.$domain/api/upload.php?a=s&s=$servername&id=$ID");
           }
          }
        echo '<div id="fb-root">
        <script>(function(d, s, id) {
          var js, fjs = d.getElementsByTagName(s)[0];
          if (d.getElementById(id)) return;
          js = d.createElement(s); js.id = id;
          js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
          fjs.parentNode.insertBefore(js, fjs);
        }(document, '."'script', 'facebook-jssdk'));</script>";
        echo '<h3>Congratulations!</h3> 
 Your shout has now been created. It can be found at <a href="http://'.$domain.'/'.$ID.'" target="_parent">http://audioshout.com/'.$ID.'</a>. Feel free to give this link to your friends or just share it with Facebook and Twitter below.<br />'.
        '<a href="https://twitter.com/share" target="_parent" class="twitter-share-button" data-url="http://'.$domain.'/'.$ID.'" data-text="I just created a new #shout on #'.$sitename.'! Check it out at " data-size="large" data-count="none">Tweet</a>
        <script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/widgets.js";fjs.parentNode.insertBefore(js,fjs);}}(document,"script","twitter-wjs");</script>
        <div class="fb-like" data-href="http://'.$domain.'/'.$ID.'" data-send="true" data-width="300" data-show-faces="false" data-action="recommend" data-colorscheme="dark">>';
    }
    }
  }
else
  {
  echo '<div id="uploadresult" style="display: none" title="Error">
    We\'re sorry, but we could not create your shout because the file you uploaded seems to be invalid. Please try again or contact us for assistance.>';
  }
require("inc/footer.php");
?>
